import { createRouter, createWebHistory } from 'vue-router'
import HelloWorld from '../components/HelloWorld.vue'
import { getWechatOpenId } from '../utils/wechatAuth'
const routes = [
    {
        path: '/',
        name: 'HelloWorld',
        component: HelloWorld,
        beforeEnter: async (to, from, next) => {
            // 进入页面前校验OpenID
            if (!localStorage.getItem('wx_openid')) {
                try {
                    // await getWechatOpenId()
                    next()
                } catch {
                    next('/error')
                }
            } else {
                next()
            }
        }
    }
]

const router = createRouter({
    history: createWebHistory(),
    routes
})

export default router